home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / diskfree / diskfree.txt < prev    next >
Text File  |  1992-11-27  |  3KB  |  100 lines

  1. For all those people who needed a function that returns the disk spaces.
  2.  
  3. The function is called as: Er% = GetDiskSpaces(Unit, DiskSpace)
  4.     where:
  5.       -GetDiskSpaces is the name of the function.
  6.        (declare in in the Global module (VB1.0) or the declarations
  7.         section of any code module (VB2.0)).
  8.  
  9.       -Unit is of Integer type with drive A being 1, drive B
  10.        being 2 and so on.
  11.  
  12.       -DiskSpace of user defined type (see below) will hold the
  13.        values returned by the function.
  14.  
  15. The function will return the total space on the drive (in clusters), the
  16. available (free space) on the drive (in clusters), the number of sectors
  17. per cluster and the number of bytes per sector. Use your VB code to make
  18. all of the other calculations.
  19.  
  20.  
  21.  
  22. The DISKFREE.FRM and DISKFREE.BAS files are for VisualBASIC 2.
  23. You will not be able to load these files in VisualBASIC 1.
  24.  
  25. If you do not have access to VB 2.0 do the following:
  26. 1. Create a new form Form1.
  27.  
  28. 2. Create the following controls on Form1:
  29.     Name        Caption
  30.     Label1        Total Space:
  31.     Label2
  32.     Label3        Free Space:
  33.     Drive1
  34.     Command1    &OK
  35.  
  36. 3. Paste the following code in the declarations section of Form1:
  37.     Sub Command1_Click ()
  38.  
  39.       Unload Form1
  40.  
  41.     End Sub
  42.  
  43. ---
  44.  
  45.     Sub Drive1_Change ()
  46.  
  47.       'The Total and the Available disk spaces are shown in Label2 and Label4.
  48.       'If interested you can also use the Bytes Per Sector, Sectors Per Cluster,
  49.       'the total Disk Clusters and the available Disk Clusters.
  50.       'Use the Panel control found in THREED.VBX with the Flood property set
  51.       'to create a bar graph type indicator.
  52.  
  53.       Dim DiskSpace As DiskFree
  54.       Dim Unit As Integer
  55.       Dim dBytesCluster As Double
  56.       Dim dTemp As Double
  57.       Unit = Asc(Drive1.Drive) - Asc("a") + 1
  58.       Er% = GetDiskSpaces(Unit, DiskSpace)
  59.       If Er% = 0 Then
  60.         dBytesCluster = DiskSpace.Bytes_Per_Sector * DiskSpace.Sectors_Per_Cluster
  61.         dTemp = dBytesCluster * DiskSpace.Total_Clusters
  62.         Label2.Caption = Format$(dTemp / 1024, "#,##0 KB")
  63.         dTemp = dBytesCluster * DiskSpace.Avail_Clusters
  64.         Label4.Caption = Format$(dTemp / 1024, "#,##0 KB")
  65.       Else
  66.         Label2.Caption = "Disk Error"
  67.         Label4.Caption = "Disk Error"
  68.       End If
  69.  
  70.     End Sub
  71.  
  72. ---
  73.  
  74.     Sub Form_Load ()
  75.  
  76.       Drive1_Change
  77.  
  78.     End Sub
  79.  
  80. 4. Create a new module named DISKFREE.BAS.
  81.  
  82. 5. Paste the following code in the declarations section of DISKFREE.BAS:
  83.     Type DiskFree
  84.         total_clusters As Long
  85.         avail_clusters As Long
  86.         sectors_per_cluster As Long
  87.         bytes_per_sector As Long
  88.     End Type
  89.  
  90.     Declare Function GetDiskSpaces Lib "diskfree.dll" (ByVal wDrive As Integer, DiskSpace As DiskFree) As Integer
  91.  
  92. 6. Press F5 to run. Select various drive from the drive list. When done
  93.    click the OK button.
  94.  
  95. The C source code is pretty well documented. (There isn't much to it.)
  96.  
  97.  
  98.                 John Castravet
  99.  
  100.